# Maintainer (MSYS2): Ray Donnelly <mingw.android@gmail.com>

_variant=-${KF5_VARIANT:-shared}
source "$(dirname ${BASH_SOURCE[0]})"/../mingw-w64-PKGBUILD-common/kde-frameworks5
_kde_f5_init_package "${_variant}" "kjs"
pkgver=5.68.0
pkgrel=1
arch=('any')
pkgdesc="Support JS scripting in KDE applications (mingw-w64-qt5${_namesuff})"
license=('LGPL')
makedepends=("${MINGW_PACKAGE_PREFIX}-extra-cmake-modules>=${pkgver}" "perl")
depends=()
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-qt5${_namesuff}" "${MINGW_PACKAGE_PREFIX}-bzip2"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-pcre${_namesuff}"
_kde_f5_add_depends "${_variant}" "${MINGW_PACKAGE_PREFIX}-kdoctools-qt5${_namesuff}>=${pkgver}"
groups=('kf5')
source=("https://download.kde.org/stable/frameworks/${pkgver%.*}/portingAids/${_basename}-${pkgver}.tar.xz"
        001-fix-build.patch)
sha256sums=('18e3d7c667aec21e9e4d0d4730ad32a10475b7db5a574a674a8b90a6f9e0cd0e'
            '9f57ba22b4d73b46d94966aba2ad0f74be3c51b3d7b92e8b922d69e1bb617cd1')

prepare() {
  cd ${_basename}-${pkgver}
  patch -p1 -i ${srcdir}/001-fix-build.patch

  cd ${srcdir}
  mkdir -p build-${CARCH}${_variant}
}

build() {
  local -a extra_config
  cd build-${CARCH}${_variant}
  if [ "${_variant}" = "-static" ]; then
    extra_config+=( -DBUILD_SHARED_LIBS=NO )
  fi

  _kde_f5_build_env
    cmake ../${_basename}-${pkgver} \
      -DCMAKE_BUILD_TYPE=$(_kde_f5_CMAKE_BUILD_TYPE) \
      "${_kde_f5_KDE_INSTALL_DIRS[@]}" \
      -DBUILD_TESTING=OFF \
      -DECM_DIR=${MINGW_PREFIX}/share/ECM \
      "${extra_config[@]}" \
      -G'MSYS Makefiles'
  make
}

package() {
  cd build-${CARCH}${_variant}
  make DESTDIR="${pkgdir}" install
}
